import {defineConfig,loadEnv} from 'vite'
import vue from '@vitejs/plugin-vue'
import vueSetupExtend from "vite-plugin-vue-setup-extend";
import path from 'path'



export default (({mode}) => {
    const VITE_API_URL: string = loadEnv(mode, process.cwd()).VITE_API_URL;

    return defineConfig({
        plugins: [
            vue(),
            vueSetupExtend()
        ],
        // 使用@
        resolve: {
            alias: {
                '@': path.resolve(__dirname, 'src')
            }
        },

        server: {
            proxy: {
                '/api': {
                    target: VITE_API_URL, // 实际请求地址
                    changeOrigin: true,
                    rewrite: (path) => path.replace(/^\/api/, ""),
                },
            },
        },
    })
})
